<template>
  <div id="table_jsgl">
    <!-- 账号状态 -->
    账号状态：
    <el-select size="small" @change="aSchange" v-model="accountStatus" placeholder="请选择">
        <el-option
          v-for="item in options"
          :key="item.id"
          :label="item.name"
          :value="item.id">
        </el-option>
    </el-select>
    <!-- 输入框 -->
    <el-input v-model="companyNameOrTel" clearable width="120" size="small" placeholder="请输入单位昵称、手机号"></el-input>
    <!-- 搜索按钮 -->
    <el-button type="primary" size="small" @click="search">搜索</el-button>

    <!-- 表格数据 -->
    <el-table :data="this.parent.data" border width="100%" :header-cell-style="{background:'#f9f9f9'}">
      <el-table-column prop="id" label="ID">
      </el-table-column>
      <el-table-column prop="companyName" label="单位名称">
      </el-table-column>
      <el-table-column prop="contactName" label="联系人姓名">
      </el-table-column>
      <el-table-column prop="tel" label="手机号">
      </el-table-column>
      <el-table-column prop="email" label="邮箱">
      </el-table-column>
      <el-table-column prop="sign_in_activities" label="单位资料">
        <template slot-scope="scope">
          <router-link :to="'../admin/hdxq?activityId='+scope.row.id">查看详情</router-link>
        </template>
      </el-table-column>
      <el-table-column prop="company_detail" label="单位详情">
        <template slot-scope="scope">
          <router-link :to="'../admin/hdxq?activityId='+scope.row.id">查看详情</router-link>
        </template>
      </el-table-column>
      <el-table-column prop="registrationTime" label="注册时间">
      </el-table-column>
      <el-table-column prop="accountStatus" label="账号状态" :formatter="AccountStatus">
      </el-table-column>
      <el-table-column prop="checkRemark" label="审核失败" v-if="this.parent.activeName == 2">
      </el-table-column>
      <el-table-column label="操作" v-if="this.parent.activeName != 2">
        <template slot-scope="scope">
          <el-button size="small" plain @click="tongguo(scope.row)">{{(parent.activeName=='1')?(scope.row.accountStatus==1?'冻结':'解冻'):"通过"}}</el-button>
          <el-button size="small" plain autofocus @click="jujue(scope.row)">{{(parent.activeName=='1')?"重置密码":"拒绝"}}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 编辑 -->
    <update1 ref="update1" :parent="this"></update1>

  </div>
</template>

<script>
  import update1 from "../update/jujue_zbfdw.vue"
  export default {
    components:{
      update1
    },
    data(){
      return{
        options:[{id:'',name:"全部"},{id:1,name:"正常"},{id:0,name:"冻结"}],
        accountStatus:'',
        companyNameOrTel:'',
      }
    },
    props: ["parent"],
    methods: {
      //下拉框改变时
      aSchange(){
        this.parent.getData();
      },
      //点击搜索
      search(){
        this.parent.getData();
      },
      //请求数据
      update(data,text){
        // 请求数据
        this.$axios.request({
          url: this.API + "/user/enterCompany/update",
          data,
          method:"post",
          // 请求成功
        }).then((res) => {
          // console.log(res)
          if (res.data.code == 0) {  // 请求成功
            this.parent.getData();   //重新请求数据
            this.$message.success(text);
            if(text == "拒绝审核成功")  this.$refs.update1.dialogFormVisible = false;
          }else{
            this.$message.error(res.data.msg)
          }
        })
      },
      // 重置密码弹窗
      mimaytanchuang(id){
        // 弹窗
        this.$confirm("确认为该用户重置密码", "重置密码", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {   //点击确定
          // 请求数据
          this.$axios.request({
            url: this.API + "/user/enterCompany/resetPWD",
            params: {id},
            method:"post",
            // 请求成功
          }).then((res) => {
            // console.log(res)
            if (res.data.code == 0) {  // 重置密码成功
              this.parent.getData();   //重新请求数据
              this.$message.success("重置成功");
            }else{
              this.$message.error(res.data.msg)
            }
          })
        }).catch(() => {   //点击取消
          this.$message({
            type: "info",
            message: "已取消重置密码"
          });
        });
      },

      // 重置密码、拒绝数据
      jujue(row){
        // 重置密码
        if(this.parent.activeName=='1'){
          this.mimaytanchuang(row.id)
        //拒绝数据
        }else{
          this.$refs.update1.id = row.id;
          this.$refs.update1.dialogFormVisible = true;
        }
      },
      // 冻结账户、解冻账户、通过审核
      tongguo(row) {
        var text = (this.parent.activeName=='1')?(row.accountStatus==1?'冻结':'解冻'):"通过";
        var id = row.id;
        var accountStatus = row.accountStatus == 1?0:1;
        console.log(this.parent.activeName)
        // 弹窗
        this.$confirm("确认为该用户"+text, "确认"+text, {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {   //点击确定
          // 请求数据
          //解冻、冻结账号
          if(this.parent.activeName=='1'){
            this.update({id,accountStatus},text+"成功");
          }else if(this.parent.activeName=='0'){
            this.update({id,checkStatus:1},text+"成功");
          }
        }).catch(() => {   //点击取消
          this.$message({
            type: "info",
            message: "已取消"+text
          });
        });
      },
      // 账户状态
      AccountStatus(row){
        return (row.accountStatus == 1)?"正常":"冻结";
        // console.log(row.accountStatus)
      }
    }
  }
</script>

<style>
  #admin_jsgl .el-table {
    margin-top: 10px;
    height: 100%;
  }

  #admin_jsgl .el-button.is-active {
    border: none;
  }

  #table_jsgl .el-input {
    width: 189px;
  }
</style>
